Ext.define('BM.controller.TokenOrders', {
    extend: 'Ext.app.Controller',
	views:  ['trade.TokenOrder','token.Tree'],
	stores: ['TreeTokens'],
	//models: ['GoodsItem','CostDetail'],
	selRoot:null,
    init: function() {
    
         this.control({
            'tokenorder>panel>panel>panel>textfield':{
            	specialkey:this.onTokenEnterKey
            },
            'tokenorder>panel>panel>panel>treepanel':{
            	itemdblclick:this.onTreeSelectToken
            },
            'tokenorder>panel>panel>tokentree':{
            	itemdblclick:this.onSelectedTreeToken
            },
            'tokenorder>panel>panel>tokentree':{
            	itemclick:this.onSelectedTreeToken
            }
        });
    },
    onTokenEnterKey:function(_field,_new,_old){
    
    	alert(_field.getValue());
    },
    onTreeSelectToken:function(view,record,item,index,e){
        
        if(this.selRoot==null)
        this.selRoot = Ext.widget("tokenorder").down("tokentree").getRootNode();
        
        this.selRoot.appendChild(record);
		this.selRoot.expand();
		/*
    	if(record.get("leaf")){
    		
    		_tree = Ext.widget('tokentree');
    	}*/
    },
    onSelectedTreeToken:function(view,record,item,index,e){
    	alert(record.get("text"));
    	if(record.get("leaf")){
    	
    	}
    },
    onSetMainOrder:function(number){
    	
    	Ext.widget("tokenorder").down("form").down
    }
});